package com.winhxd.b2c.product.controller;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.product.condition.ProductTagCondition;
import com.winhxd.b2c.common.domain.product.model.ProductTag;
import com.winhxd.b2c.common.feign.product.ProductTagServiceClient;
import com.winhxd.b2c.product.service.ProductTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品服务管理
 * @author luosixiang
 */
@Api(value = "ProductTag Perfection", tags ="product ProductTag")
@RestController
public class ProductTagController implements ProductTagServiceClient {

    private Logger logger = LoggerFactory.getLogger(ProductTagController.class);

    @Autowired
    private ProductTagService productTagService;

    @ApiOperation(value = "根据服务id编辑商品服务信息状态")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<Integer> modifyProductTagStatusById(@RequestBody ProductTagCondition condition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        Integer i = productTagService.modifyProductTagStatusById(condition);
        result.setData(i);
        return result;
    }

    @ApiOperation(value = "根据服务id删除该商品服务")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<Integer> deleteProductTagById(@PathVariable(value = "id") long id) {
        ResponseResult<Integer> result = new ResponseResult<>();
        Integer i = productTagService.deleteProductTagById(id);
        result.setData(i);
        return result;
    }

    @ApiOperation(value = "查询商品服务列表")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<PagedList<ProductTag>> findProductTagList(@RequestBody ProductTagCondition productTagCondition) {
        ResponseResult<PagedList<ProductTag>> result = new ResponseResult<>();
        PagedList<ProductTag> list = productTagService.findProductTagList(productTagCondition);
        result.setData(list);
        return result;
    }

    /**
     * 编辑服务列表回显
     * @param id
     * @return
     */
    @ApiOperation(value = "根据服务id查询商品服务")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<ProductTag> getProductTagById(@PathVariable(value = "id") long id) {
        ResponseResult<ProductTag> result = new ResponseResult<>();
        ProductTag productTag = productTagService.getProductTagById(id);
        result.setData(productTag);
        return result;
    }

    @ApiOperation(value = "新增商品服务")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<Integer> savaProductTag(@RequestBody ProductTagCondition condition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        Integer i = productTagService.savaProductTag(condition);
        result.setData(i);
        return result;
    }

    @ApiOperation(value = "保存商品服务信息")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<Integer> savaOrUpdateProductTag(@RequestBody ProductTagCondition condition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        Integer i = productTagService.savaOrUpdateProductTag(condition);
        result.setData(i);
        return result;
    }

    @ApiOperation(value = "根据条件查询商品服务信息")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @Override
    public ResponseResult<List<ProductTag>> findProductTagByModel(@RequestBody ProductTagCondition condition) {
        ResponseResult<List<ProductTag>> result = new ResponseResult<>();
        List<ProductTag> list = productTagService.findProductTagByModel(condition);
        result.setData(list);
        return result;
    }


}
